//
//  QDSelectDiagnosisController.m
//  simulateQuickDoctor
//
//  Created by 梁家伟 on 17/3/25.
//  Copyright © 2017年 PipiXia. All rights reserved.
//

#import "QDSelectDiagnosisController.h"
#import "QDBaseTableViewCell.h"

@interface QDSelectDiagnosisController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,weak)UITableView* diagnosisList;
@end

@implementation QDSelectDiagnosisController{
    NSMutableArray* _diagnosisData;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _diagnosisData = [NSMutableArray array];
    
    [self loadData];
}

static NSString* diagnosisCell = @"diagnosis";

- (void)setupUI{
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    UITableView* diagnosisList = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
    diagnosisList.dataSource =self;
    diagnosisList.delegate = self;
    
    [self.view addSubview:diagnosisList];
    
    [diagnosisList mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    
    _diagnosisList = diagnosisList;
    
    
    [diagnosisList registerClass:[QDBaseTableViewCell class] forCellReuseIdentifier:diagnosisCell];
    
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    return _diagnosisData.count;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSUInteger diagnosisType = [_diagnosisData[indexPath.row][@"diagnosis_type"] integerValue];
 
    NSString* diagnosisName = _diagnosisData[indexPath.row][@"diagnosis_name"];
    
    self.callBackBlock(diagnosisType,diagnosisName);
    
    [self.navigationController popViewControllerAnimated:YES];
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    QDBaseTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:diagnosisCell forIndexPath:indexPath];

    cell.textLabel.text = _diagnosisData[indexPath.row][@"diagnosis_name"];
    
    return cell;
}


- (void)loadData{
    
    NSArray * diagnosisType = @[
                                @{@"diagnosis_type":@2,
                                  @"diagnosis_name":@"手术治疗"
                                  },
                                
                                @{@"diagnosis_type":@3,
                                  @"diagnosis_name":@"保留治疗"
                                  },
                                
                                @{@"diagnosis_type":@4,
                                  @"diagnosis_name":@"药物治疗"
                                  }
                                ];
    
    [_diagnosisData addObjectsFromArray:diagnosisType];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
